home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / bsd / netinet / in.h < prev    next >
Text File  |  1995-02-14  |  7KB  |  238 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1987 Carnegie-Mellon University
  4.  * All rights reserved.  The CMU software License Agreement specifies
  5.  * the terms and conditions for use and redistribution.
  6.  */
  7. /*
  8.  * Copyright (c) 1982, 1986 Regents of the University of California.
  9.  * All rights reserved.
  10.  * Redistribution and use in source and binary forms are permitted
  11.  * provided that this notice is preserved and that due credit is given
  12.  * to the University of California at Berkeley. The name of the University
  13.  * may not be used to endorse or promote products derived from this
  14.  * software without specific prior written permission. This software
  15.  * is provided ``as is'' without express or implied warranty.
  16.  *
  17.  *    @(#)in.h    7.5 (Berkeley) 2/22/88
  18.  *
  19.  * HISTORY
  20.  * 11-Jul-93  Mac Gillon (mgillon) at NeXT
  21.  *    Integrated MULTICAST support
  22.  *
  23.  * 26-Sep-89  Morris Meyer (mmeyer) at NeXT
  24.  *    NFS 4.0 Changes: Added definition of official port numbers.
  25.  */ 
  26.  
  27. #ifndef    _IN_
  28. #define    _IN_
  29.  
  30. #ifdef    KERNEL
  31. #import    <sys/protosw.h>
  32. #import    <sys/domain.h>
  33. #endif    KERNEL
  34.  
  35. /*  @(#)in.h    2.2 88/06/10 4.0NFSSRC; from    7.1 (Berkeley) 6/5/86 */
  36.  
  37. /*
  38.  * Constants and structures defined by the internet system,
  39.  * Per RFC 790, September 1981.
  40.  */
  41.  
  42. /*
  43.  * Protocols
  44.  */
  45. #define    IPPROTO_IP        0        /* dummy for IP */
  46. #define    IPPROTO_ICMP        1        /* control message protocol */
  47. #define    IPPROTO_IGMP        2        /* group mgmt protocol */
  48. #define    IPPROTO_GGP        3        /* gateway^2 (deprecated) */
  49. #define    IPPROTO_TCP        6        /* tcp */
  50. #define    IPPROTO_EGP        8        /* exterior gateway protocol */
  51. #define    IPPROTO_PUP        12        /* pup */
  52. #define    IPPROTO_UDP        17        /* user datagram protocol */
  53. #define    IPPROTO_IDP        22        /* xns idp */
  54.  
  55. #define    IPPROTO_RAW        255        /* raw IP packet */
  56. #define    IPPROTO_MAX        256
  57.  
  58. /*
  59.  * Port/socket numbers: network standard functions
  60.  */
  61. #define    IPPORT_ECHO        7
  62. #define    IPPORT_DISCARD        9
  63. #define    IPPORT_SYSTAT        11
  64. #define    IPPORT_DAYTIME        13
  65. #define    IPPORT_NETSTAT        15
  66. #define    IPPORT_FTP        21
  67. #define    IPPORT_TELNET        23
  68. #define    IPPORT_SMTP        25
  69. #define    IPPORT_TIMESERVER    37
  70. #define    IPPORT_NAMESERVER    42
  71. #define    IPPORT_WHOIS        43
  72. #define    IPPORT_MTP        57
  73.  
  74. /*
  75.  * Port/socket numbers: host specific functions
  76.  */
  77. #define    IPPORT_TFTP        69
  78. #define    IPPORT_RJE        77
  79. #define    IPPORT_FINGER        79
  80. #define    IPPORT_TTYLINK        87
  81. #define    IPPORT_SUPDUP        95
  82.  
  83. /*
  84.  * UNIX TCP sockets
  85.  */
  86. #define    IPPORT_EXECSERVER    512
  87. #define    IPPORT_LOGINSERVER    513
  88. #define    IPPORT_CMDSERVER    514
  89. #define    IPPORT_EFSSERVER    520
  90.  
  91. /*
  92.  * UNIX UDP sockets
  93.  */
  94. #define    IPPORT_BIFFUDP        512
  95. #define    IPPORT_WHOSERVER    513
  96. #define    IPPORT_ROUTESERVER    520    /* 520+1 also used */
  97.  
  98. /*
  99.  * Ports < IPPORT_RESERVED are reserved for
  100.  * privileged processes (e.g. root).
  101.  * Ports > IPPORT_USERRESERVED are reserved
  102.  * for servers, not necessarily privileged.
  103.  */
  104. #define    IPPORT_RESERVED        1024
  105. #define    IPPORT_USERRESERVED    5000
  106.  
  107. /*
  108.  * Link numbers
  109.  */
  110. #define    IMPLINK_IP        155
  111. #define    IMPLINK_LOWEXPER    156
  112. #define    IMPLINK_HIGHEXPER    158
  113.  
  114. /*
  115.  * Internet address (a structure for historical reasons)
  116.  */
  117. struct in_addr {
  118. #if    NeXT
  119.     union {
  120.         struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  121.         struct { u_short s_w1,s_w2; } S_un_w;
  122.         u_long S_addr;
  123.     } S_un;
  124. #define    s_addr    S_un.S_addr    /* can be used for most tcp & ip code */
  125. #define    s_host    S_un.S_un_b.s_b2    /* host on imp */
  126. #define    s_net    S_un.S_un_b.s_b1    /* network */
  127. #define    s_imp    S_un.S_un_w.s_w2    /* imp */
  128. #define    s_impno    S_un.S_un_b.s_b4    /* imp # */
  129. #define    s_lh    S_un.S_un_b.s_b3    /* logical host */
  130. #else    NeXT
  131.     u_long s_addr;
  132. #endif    NeXT
  133. };
  134.  
  135. /*
  136.  * Definitions of bits in internet address integers.
  137.  * On subnets, the decomposition of addresses to host and net parts
  138.  * is done according to subnet mask, not the masks here.
  139.  */
  140. #define    IN_CLASSA(i)        (((long)(i) & 0x80000000) == 0)
  141. #define    IN_CLASSA_NET        0xff000000
  142. #define    IN_CLASSA_NSHIFT    24
  143. #define    IN_CLASSA_HOST        0x00ffffff
  144. #define    IN_CLASSA_MAX        128
  145.  
  146. #define    IN_CLASSB(i)        (((long)(i) & 0xc0000000) == 0x80000000)
  147. #define    IN_CLASSB_NET        0xffff0000
  148. #define    IN_CLASSB_NSHIFT    16
  149. #define    IN_CLASSB_HOST        0x0000ffff
  150. #define    IN_CLASSB_MAX        65536
  151.  
  152. #define    IN_CLASSC(i)        (((long)(i) & 0xe0000000) == 0xc0000000)
  153. #define    IN_CLASSC_NET        0xffffff00
  154. #define    IN_CLASSC_NSHIFT    8
  155. #define    IN_CLASSC_HOST        0x000000ff
  156.  
  157. #define    IN_CLASSD(i)        (((long)(i) & 0xf0000000) == 0xe0000000)
  158. #define    IN_CLASSD_NET        0xf0000000    /* These ones aren't really */
  159. #define    IN_CLASSD_NSHIFT    28        /* net and host fields, but */
  160. #define    IN_CLASSD_HOST        0x0fffffff    /* routing needn't know.    */
  161. #define    IN_MULTICAST(i)        IN_CLASSD(i)
  162.  
  163. #define    IN_EXPERIMENTAL(i)    (((long)(i) & 0xe0000000) == 0xe0000000)
  164. #define    IN_BADCLASS(i)        (((long)(i) & 0xf0000000) == 0xf0000000)
  165.  
  166. #define    INADDR_ANY        (u_long)0x00000000
  167. #define INADDR_LOOPBACK        (u_long)0x7f000001
  168. #define    INADDR_BROADCAST    (u_long)0xffffffff    /* must be masked */
  169.  
  170. #define    INADDR_UNSPEC_GROUP    (u_long)0xe0000000    /* 224.0.0.0   */
  171. #define    INADDR_ALLHOSTS_GROUP    (u_long)0xe0000001    /* 224.0.0.1   */
  172. #define    INADDR_MAX_LOCAL_GROUP     (u_long)0xe00000ff    /* 224.0.0.255 */
  173.  
  174. #ifndef KERNEL
  175. #define    INADDR_NONE        0xffffffff        /* -1 return */
  176. #endif
  177.  
  178. #define    IN_LOOPBACKNET        127            /* official! */
  179.  
  180. /*
  181.  * Define a macro to stuff the loopback address into an Internet address
  182.  */
  183. #define IN_SET_LOOPBACK_ADDR(a)    {(a)->sin_addr.s_addr  = htonl(INADDR_LOOPBACK); \
  184.     (a)->sin_family = AF_INET;}
  185.  
  186. /*
  187.  * Socket address, internet style.
  188.  */
  189. struct sockaddr_in {
  190.     short    sin_family;
  191.     u_short    sin_port;
  192.     struct    in_addr sin_addr;
  193.     char    sin_zero[8];
  194. };
  195.  
  196. /*
  197.  * Options for use with [gs]etsockopt at the IP level.
  198.  */
  199. #define    IP_OPTIONS        1    /* set/get IP per-packet options */
  200. #define    IP_TIMETOLIVE        2    /* set/get IP time-to-live value */
  201. #define    IP_MULTICAST_IF        3    /* set/get IP multicast interface  */
  202. #define    IP_MULTICAST_TTL    4    /* set/get IP multicast timetolive */
  203. #define    IP_MULTICAST_LOOP    5    /* set/get IP multicast loopback   */
  204. #define    IP_ADD_MEMBERSHIP    6    /* add  an IP group membership     */
  205. #define    IP_DROP_MEMBERSHIP    7    /* drop an IP group membership     */
  206.  
  207. #define    IP_DEFAULT_MULTICAST_TTL   1    /* normally limit m'casts to 1 hop  */
  208. #define    IP_DEFAULT_MULTICAST_LOOP  1    /* normally hear sends if a member  */
  209. #define    IP_MAX_MEMBERSHIPS         20    /* per socket; must fit in one mbuf */
  210.  
  211. /*
  212.  * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
  213.  */
  214. struct ip_mreq {
  215.     struct in_addr    imr_multiaddr;    /* IP multicast address of group */
  216.     struct in_addr    imr_interface;    /* local IP address of interface */
  217. };
  218.  
  219. /*
  220.  * Conversion between host
  221.  * and network byte order.
  222.  */
  223. #import <architecture/byte_order.h>
  224.  
  225. #define ntohl(x)    NXSwapBigLongToHost(x)
  226. #define ntohs(x)    NXSwapBigShortToHost(x)
  227. #define htonl(x)    NXSwapHostLongToBig(x)
  228. #define htons(x)    NXSwapHostShortToBig(x)
  229.  
  230. #ifdef    KERNEL
  231. extern    struct domain inetdomain;
  232. extern    struct protosw inetsw[];
  233. struct    in_addr in_makeaddr();
  234. u_long    in_netof(), in_lnaof();
  235. #endif
  236.  
  237. #endif    _IN_
  238.